<?php
require_once 'header.php';

//categories
$crs = $xoopsDB->query("SELECT * FROM $table_cat");
$cats = array();
while ($cRow = $xoopsDB->fetchArray($crs)) {
	$cats[$cRow['cid']] = htmlspecialchars($cRow['ctitle'], ENT_QUOTES);
}

// access best 50
$num = 50;

// items
$cid_where = '';
if (isset($_GET['cid']) && !empty($_GET['cid'])) {
	$cid = intval($_GET['cid']);
	$cid_where = 'AND cid=' . $cid;
	$bread[] = array('name' => $cats[$cid], 'url' => $mydirurl . '/index.php?cid='. $cid);
}
$sql = "SELECT * FROM $table_items WHERE stats>0 $cid_where ORDER BY clicks DESC";
$rs = $xoopsDB->query($sql, $num, 0);

$items = array();
while ($row = $xoopsDB->fetchArray($rs)) {
	$items[] = array(
		'lid'           => $row['lid'],
		'cid'           => $row['cid'],
		'regdate'       => $row['regdate'],
		'clicks'        => $row['clicks'],
	//	'ASIN'          => htmlspecialchars($row['ASIN'], ENT_QUOTES),
		'title'         => htmlspecialchars($row['title'], ENT_QUOTES),
	);
}

//---------------------------------------------------------------------------------
$xoopsOption['template_main'] = $mydirname .'_access.html';
require XOOPS_ROOT_PATH.'/header.php';

$xoopsTpl->assign('items', $items);
$xoopsTpl->assign('num', $num);
$xoopsTpl->assign('cats', $cats);
$xoopsTpl->assign($basic_assign);

$page_title = sprintf(_MD_MINIAMAZON_ACCESS_BEST, $num);
$xoopsTpl->assign('access_best', $page_title);
$bread[] = array('name' => $page_title);
$xoopsTpl->assign('xoops_breadcrumbs', $bread);
$xoopsTpl->assign('xoops_pagetitle', $xoopsModule->getVar('name') .' : '. $page_title);

$css_file = '<link rel="stylesheet" href="'. $mydirurl .'/?act=css" type="text/css" media="all" />';
$xoopsTpl->assign('xoops_module_header', $css_file . $xoopsTpl->get_template_vars("xoops_module_header"));

require_once XOOPS_ROOT_PATH.'/footer.php';
//---------------------------------------------------------------------------------
